package web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ProdDao;

import entity.Prod;

public class AddProdServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");

		String prodName = request.getParameter("prodname");
		String price = request.getParameter("price");
		
		try{
			Prod prod=new Prod();
			prod.setProdname(prodName);
			prod.setPrice(Float.parseFloat(price));
			ProdDao dao = new ProdDao();
			dao.add(prod);
			response.sendRedirect("home.jsp");
		} catch(NumberFormatException e) {
			response.sendRedirect("add.jsp?code=10002");
		}
		
	}
	
	

}
